//
//  XYChatViewController.h
//  十年少
//
//  Created by 尧的mac on 15/11/28.
//  Copyright © 2015年 xxy.icom. All rights reserved.
//
#import "WLKeyBordVIew.h"


@interface WLKeyBordVIew()<UITextFieldDelegate>

@property (nonatomic,strong) UIImageView *backImageView;
@property (nonatomic,strong) UIButton *voiceBtn;
@property (nonatomic,strong) UIButton *imageBtn;
@property (nonatomic,strong) UIButton *addBtn;
@property (nonatomic,strong) UIButton *speakBtn;

@end

@implementation WLKeyBordVIew

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialData];
    }
    return self;
}

-(UIButton *)buttonWith:(NSString *)noraml hightLight:(NSString *)hightLight action:(SEL)action
{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:noraml] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:hightLight] forState:UIControlStateHighlighted];
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    return btn;
}
-(void)initialData
{
    
    self.backImageView=[[UIImageView alloc]initWithFrame:self.bounds];
    self.backImageView.image=[UIImage imageNamed:@"toolbar_bottom_bar.png"];
    [self addSubview:self.backImageView];
    
    // 声音按钮
    self.voiceBtn = [self buttonWith:@"chat_bottom_voice_nor.png" hightLight:@"chat_bottom_voice_press.png" action:@selector(voiceBtnPress:)];
    [self.voiceBtn setFrame:CGRectMake(0, 0, 44, 44)];
    [self addSubview:self.voiceBtn];
    
    
    // 文本输入框
    self.textField = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_voiceBtn.frame), 0, CGRectGetWidth(self.frame) - 44*3, 44)];
    self.textField.returnKeyType = UIReturnKeySend;
    self.textField.font = [UIFont fontWithName:@"HelveticaNeue" size:16];
    
    self.textField.background =[ UIImage imageNamed:@"chat_bottom_textfield.png"];
    self.textField.delegate = self;
    [self addSubview:self.textField];
    
    
    //textFiled左边显示的view空的
    self.textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
    self.textField.leftViewMode = UITextFieldViewModeAlways;
    
    
    // 表情图片
    self.imageBtn = [self buttonWith:@"chat_bottom_smile_nor.png" hightLight:@"chat_bottom_smile_press.png" action:nil];
    [self.imageBtn setFrame:CGRectMake(CGRectGetMaxX(_textField.frame), 0, 44, 44)];
    [self addSubview:self.imageBtn];
    
    // 添加更多按钮
    self.addBtn = [self buttonWith:@"chat_bottom_up_nor.png" hightLight:@"chat_bottom_up_press.png" action:nil];
    [self.addBtn setFrame:CGRectMake(CGRectGetMaxX(_imageBtn.frame), 0, 44, 44)];
    [self addSubview:self.addBtn];
    
    [self.speakBtn setFrame:self.textField.frame];
    [self.speakBtn setTitle:@"按住 说话" forState:UIControlStateNormal];
    [self.speakBtn setBackgroundImage:[UIImage imageNamed:@"chat_bottom_textfield.png"] forState:UIControlStateNormal];
    [self.speakBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.speakBtn setTitle:@"松开 关闭" forState:(UIControlState)UIControlEventTouchDown];
    [self.speakBtn setBackgroundColor:[UIColor whiteColor]];
    self.speakBtn.hidden = YES;
    [self addSubview:self.speakBtn];
}

-(void)voiceBtnPress:(UIButton *)voice
{
    NSString *normal,*hightLight;
    if(self.speakBtn.hidden == YES){
        
        self.speakBtn.hidden = NO;
        self.textField.hidden = YES;
        
        NSLog(@"%@", NSStringFromCGRect(self.speakBtn.frame));
       normal = @"chat_bottom_keyboard_nor.png";
       hightLight = @"chat_bottom_keyboard_press.png";
    
    }else{
    
        self.speakBtn.hidden = YES;
        self.textField.hidden = NO;
        normal = @"chat_bottom_voice_nor.png";
        hightLight = @"chat_bottom_voice_press.png";
    
    }
    [voice setImage:[UIImage imageNamed:normal] forState:UIControlStateNormal];
    [voice setImage:[UIImage imageNamed:hightLight] forState:UIControlStateHighlighted];
}


-(void)imageBtnPress:(UIButton *)image
{
    
    
}
-(void)addBtnPress:(UIButton *)image
{
    
    
}

/*
 -(void)touchDown:(UIButton *)voice
{
     //    self.speakBtn
     //开始录音
    if([self.delegate respondsToSelector:@selector(beginRecord)]){
     
        [self.delegate beginRecord];
    }
    NSLog(@"开始录音");
}
-(void)speakBtnPress:(UIButton *)voice
{
     //结束录音
     
     if([self.delegate respondsToSelector:@selector(finishRecord)]){
     
        [self.delegate finishRecord];
     }
     NSLog(@"结束录音");
 }
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if([self.delegate respondsToSelector:@selector(KeyBordView:textFiledBegin:)]){
        
        [self.delegate KeyBordView:self textFiledBegin:textField];
    }
    return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if([self.delegate respondsToSelector:@selector(KeyBordView:textFiledReturn:)]){
    
        [self.delegate KeyBordView:self textFiledReturn:textField];
    }
    return YES;
}
*/
@end
